<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>#</th>
            <th>昵称</th>
            <th>账号</th>
            <th>所属角色</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
    {{if !empty($adminlist)}}
    {{foreach $adminlist as $k=>$v}}
    <tr>
        <td class="key_id" tmp-id="{{$v['id']}}">{{($k+1)}}</td>
        <td>{{$v['real_name']}}</td>
        <td>{{$v['account']}}</td>
        <td>{{$v['name']}}</td>
        <td>
            <div class="switch">
                <div class="onoffswitch">
                    <input type="checkbox" {{if $v['status']}}checked{{/if}} class="onoffswitch-checkbox" id="example{{$k}}">
                    <label class="onoffswitch-label" for="example{{$k}}">
                        <span class="onoffswitch-inner"></span>
                        <span class="onoffswitch-switch"></span>
                    </label>
                </div>
            </div>
        </td>
        <td>
            <a data-toggle="modal" class="btn btn-xs btn-outline btn-warning admin-edit" href="#modal-form-edit">编辑</a>
            <a class="btn btn-xs btn-outline btn-danger admin-delete" href="javascript:;">删除</a>
        </td>
    </tr>
    {{/foreach}}
    {{else}}
    <tr class="no-records-found t-align">
        <td colspan="6">没有找到匹配的记录</td>
    </tr>
    </tbody>
    {{/if}}
</table>

<div id="page-div" class="row">
    <div class="col-sm-6">
        <div id="editable_info" class="dataTables_info" role="alert" aria-live="polite" aria-relevant="all">显示 <span class="start">0</span> 到 <span class="end">0</span> 项，共 {{$total}} 项</div>
    </div>
    <div class="col-sm-6">
        <div id="editable_paginate" class="dataTables_paginate paging_simple_numbers">
            <ul class="pagination">
                {{if !empty($showpage)}}
                <li id="page-first" class="paginate_button previous" aria-controls="editable" tabindex="0">
                    <a href="{{$module}}/power/ajaxAdminList/1">首页</a>
                </li>
                {{$showpage}}
                <li id="page-last" class="paginate_button next" aria-controls="editable" tabindex="0">
                    <a href="{{$module}}/power/ajaxAdminList/{{$last_page}}">尾页</a>
                </li>
                {{/if}}
            </ul>
        </div>
    </div>
</div>


<script type="text/javascript">
$(function(){
    // 显示从1到10项，共xx项
    var start = $("#ajaxAdminList table tbody tr:first").find('.key_id').html();
    var end = $("#ajaxAdminList table tbody tr:last").find('.key_id').html();
    $("#page-div .start").html(start);
    $("#page-div .end").html(end);

    var time = $("#adminList").find("input[name='time']").val();
    // 上一页下一页改为post
    $("#page-div .paginate_button").click(function (event) {
        if($(this).hasClass('active')) return false;
        var url = $(this).children('a').attr('href');
        posth(url,null,function (r) {
            $('#ajaxAdminList').html(r);
        });
        // return false;
        event.preventDefault();
    });

    // 获取编辑管理员
    $("#ajaxAdminList .admin-edit").click(function(){
        var url = module + '/power/getAdminInfo';
        var admin_id = $(this).parent('td').parent('tr').find('td:first').attr('tmp-id');
        $.post(url,{id:admin_id},function(r){
            $("#modal-form-edit").find("input[name='real_name']").val(r.real_name);
            $("#modal-form-edit").find("input[name='account']").val(r.account);
            $("#modal-form-edit").find("input[name='role_id']").val(r.role_id);
            $("#modal-form-edit").find("input[name='id']").val(r.id);
            $("#modal-form-edit").find("input[name='password']").val('');
            $("#modal-form-edit").find("input[name='confirm_password']").val('');
        });
    });

    // 编辑管理员
    $("#modal-form-edit form").submit(function(e){
        
        submitAjax($(this),function(res){
            if(res.success){
                $('.close').trigger('click');
                layer.msg(res.msg,{icon: 1,time: 1200},function(){
                    getAdminList();
                });
            }else{
                layer.msg(res.msg,{icon: 2,time: 1200});
            }
        });
        return false;
    });

    // 删除管理员
    $("#ajaxAdminList .admin-delete").click(function(){
        var $this = $(this);
        layer.prompt({title: '输入管理员密码口令，并确认', formType: 1}, function(pass, index){
            layer.close(index);
            post(module+'/power/verifyPass',{pass:pass},function(checkres){
                if(checkres.success==true){
                    var url = module + '/power/ajaxDelAdmin';
                    var admin_id = $this.parent('td').parent('tr').find('td:first').attr('tmp-id');
                    ajaxStatus = true;
                    post(url,{id:admin_id},function(res){
                        if(res.success==true){
                            $('.close').trigger('click');
                            layer.msg(res.msg,{icon:1},function(){
                                getAdminList();
                            });
                        }else{
                            layer.msg(res.msg,{icon:2});
                        }
                    })
                }else{
                    layer.msg(checkres.msg,{icon:2});
                }
            });
        });
        
    });
        
})

</script>



